package logic

import (
	"30zk/rpc/model/mysql"
	"30zk/rpc/pkg"
	"context"
	"fmt"

	"30zk/rpc/internal/svc"
	"30zk/rpc/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *order.LoginRequest) (*order.LoginResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	err := u.GetCreate(in.Phone)
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	if pkg.PwdMd5(in.Password) != u.Password {
		return nil, fmt.Errorf("密码错误")
	}
	return &order.LoginResponse{
		Id: int64(u.ID),
	}, nil
}
